package com.lianzhihui.romeex.mvp.model;

import android.content.Context;

import com.lianzhihui.romeex.bean.ZZPostBean;
import com.lianzhihui.romeex.net.APIConstant;
import com.lianzhihui.romeex.net.HttpManager;
import com.lianzhihui.romeex.net.HttpManagerCallback;
import com.lianzhihui.romeex.net.ResultData;
import com.lianzhihui.romeex.utils.LogUtil;
import com.zhouyou.http.exception.ApiException;
import com.zhouyou.http.model.HttpParams;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Description: 转账业务
 * Author: RAMON
 * CreateDate: 2020/11/10 3:49 PM
 * UpdateUser:
 * UpdateDate:
 * UpdateRemark:
 * Version:
 */
public class ZZModel {

    Context context;
    ZZInterface callback;

    public ZZModel(Context context, ZZInterface callback) {
        this.context = context;
        this.callback = callback;
    }

    public void zhuanZhangBiz(ZZPostBean bean) {

        HttpParams params = new HttpParams();
        params.put("targetUserAddress", bean.getTargetUserAddress());
        params.put("coinNameCobo", bean.getCoinNameCobo());
        params.put("coinName", bean.getCoinName());
        params.put("remark", bean.getRemark());
        params.put("chainType", bean.getChainType() + "");
        params.put("amount", bean.getAmountLarge() + "");
        new HttpManager(context, new HttpManagerCallback() {
            @Override
            public void onSuccess(ResultData o) {
                try {
                    JSONObject obj = new JSONObject(o.getData().toString());
                    callback.onZZSuccess(obj.optString("transactionHashcode"));
                } catch (JSONException e) {
                    LogUtil.error("json", e.toString());
                }

            }

            @Override
            public void onError(ApiException e) {
                callback.onZZFail();
            }
        }).post(APIConstant.ZHUANZHANG, params);
    }

}
